package com.fbee.smartcommunities.vo;

import com.fbee.smartcommunities.core.ResultCode;
import lombok.Getter;

/**
 * ClassName: com.fbee.smartcommunities.vo
 * Datetime: 2024/8/16 下午4:27
 * Description:
 *
 * @author 汪佳泉
 * @version 1.0
 * @since 1.0
 */
@Getter
public class ResultVO<T> {
    // 状态码
    private final Integer code;
    // 主体内容，如查询数据
    private final T content;
    // 请求信息，如 当前请求失败，请联系管理员 等
    private final String message;

    public ResultVO(ResultCode code, T content, String message) {
        this.code = code.getValue();
        this.content = content;
        this.message = message;
    }

    public static <T> ResultVO<T> getInstance(ResultCode code, T content, String message){
        return new ResultVO<T>(code,content,message);
    }

    public static <T> ResultVO<T> success(T content, String message){
        return new ResultVO<T>(ResultCode.SUCCESS,content,message);
    }

    public static <T> ResultVO<T> success(T content){
        return new ResultVO<T>(ResultCode.SUCCESS,content,null);
    }

    // 出错需要返回内容
    public static <T> ResultVO<T> failed(T content, String message){
        return new ResultVO<T>(ResultCode.FAILED,content,message);
    }

    // 出错但不需要返回内容，只需要返回信息
    public static <T> ResultVO<T> failed(String message){
        return failed(null,message);
    }

    public static <T> ResultVO<T> forbid(){
        return new ResultVO<T>(ResultCode.FORBID,null,"该用户没有这个权限");
    }

    public static <T> ResultVO<T> unLogin(String message){
        return new ResultVO<T>(ResultCode.UNLOGIN,null,message);
    }

}
